package bdqn.t09.service.impl;

import bdqn.t09.dao.AsKeywordsMapper;
import bdqn.t09.pojo.AsCustoms;
import bdqn.t09.pojo.AsKeywords;
import bdqn.t09.service.AsKeywordsService;
import bdqn.t09.util.Pageinfo;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.annotation.Resources;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class AsKeywordsServiceImpl implements AsKeywordsService {

    @Resource
    public AsKeywordsMapper mapper;

    @Override
    public int deleteByPrimaryKey(Long id) {
        return mapper.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(AsKeywords record) {
        return mapper.insert(record);
    }

    @Override
    public int insertSelective(AsKeywords record) {
        return mapper.insertSelective(record);
    }

    @Override
    public AsKeywords selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<AsKeywords> asKeywordsList() {
        return mapper.asKeywordsList();
    }

    @Override
    public int asKeywordsList2() {
        return mapper.asKeywordsList2();
    }


    @Override
    public int updateByPrimaryKeySelective(AsKeywords record) {
        return mapper.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(AsKeywords record) {
        return mapper.updateByPrimaryKey(record);
    }

    @Override
    public Pageinfo selectKeyWordFen(String keywords, Integer pageindex, Integer row) {
        Pageinfo pageinfo=new Pageinfo();
        pageinfo.setCurrIndex(pageindex);
        pageinfo.setRows(row);
        int count = mapper.count(keywords);
        pageinfo.setCount(count);
        Map map=new HashMap();
        int offset = (pageindex-1)*row;
        map.put("keywords",keywords);
        map.put("offset",offset);
        map.put("rows",row);
        List<AsKeywords> asCustoms = mapper.findAsKeywords(map);
        pageinfo.setList(asCustoms);
        return  pageinfo;
    }

    @Override
    public int updateByApp(int id) {
        return mapper.updateByApp(id);
    }

    @Override
    public int updateBykeywords(AsKeywords record) {
        return mapper.updateBykeywords(record);
    }

    public Pageinfo selectAllPortal(Integer currIndex, Integer rows, String keywords, String customname) {
        Pageinfo pageinfo = new Pageinfo();
        pageinfo.setCurrIndex(currIndex);
        pageinfo.setRows(rows);
        int count = mapper.count();
        pageinfo.setCount(count);
        Integer index = (currIndex - 1) * rows;
        List<AsKeywords> asKeywords = mapper.selectAllPortal(index, rows, keywords, customname);
        pageinfo.setList(asKeywords);
        return pageinfo;
    }

    @Override
    public AsKeywords chaKeywords(String keywords) {
        List<AsKeywords> asKeywords = mapper.chaKeywords(keywords);
        if(asKeywords.size() != 0){
            return asKeywords.get(0);
        }
        return null;
    }
}
